/** A simple RMI server implementation and Server Application
 
    The server implementation
      - extends UnicastRemoteObject which is a subclass of RemoteServer.
	The RemoteSever is a subclass of RemoteObject.
      - implements SimpleServer1 interface.
    The server application
      - Define a remote server object, bind object to an unique name
      - The server application will be defined within server class.

   After server implementation is done,
      - compile the server (javac SimpleServerImpl.java),
      - generate stub and skeleton ( rmic SimpleServer1Impl),
      - start rmi registry to manage remote server object (rmiregistry)
      - start server application which is in SimpleServer1Impl.java
		( java SimpleServer1Impl )
*/

import java.rmi.*;
import java.rmi.server.*;

public class SimpleServer1Impl extends UnicastRemoteObject
			       implements SimpleServer1 {

    static final long serialVersionUID = 123456789;

    public SimpleServer1Impl() throws RemoteException {}

    public void write(String clientName, String msg ) throws RemoteException {
	System.out.println(clientName + ": " + msg);
    }

    // Remote server application: define a server object and bind remote 
    // server object with a unique name.
    public static void main(String args[] ) {
       try {

	SimpleServer1Impl svrObj = new SimpleServer1Impl();

        // Method 1. Two statements without running rmiregistry.
	// Registry reg = LocateRegistry.createRegistry( 3941 );
	// reg.rebind( "//localhost:3941/SimpleServer1",  svrObj);

	// Method 2: rum "rmiregistry 3941 &" first and use the following statememnt:
	// sleipnir likes method 2 instead of method 1.
	Naming.rebind( "//localhost:3941/SimpleServer1" , svrObj);

       } catch (Exception e) 
	{ e.printStackTrace(); }
    }

}
